package com.ruoyi.project.common.recommend.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.ruoyi.common.constant.RedisKey;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.recommend.domain.AppRecommend;
import com.ruoyi.project.common.recommend.mapper.AppRecommendMapper;
import com.ruoyi.project.common.recommend.service.IAppRecommendService;

/**
 * 换量系统Service业务层处理
 * 
 * @author shixiangwen
 * @date 2020-01-13
 */
@Service
@DataSource(value = DataSourceType.DICT)
public class AppRecommendServiceImpl implements IAppRecommendService {

	@Autowired
	private AppRecommendMapper appRecommendMapper;

	@Autowired
	@Qualifier("dictRedisTemplate")
	RedisTemplate<String, String> redisTemplate;

	/**
	 * 查询换量系统
	 * 
	 * @param appid 换量系统ID
	 * @return 换量系统
	 */
	@Override
	public AppRecommend selectAppRecommendById(Long appid) {
		return appRecommendMapper.selectAppRecommendById(appid);
	}

	/**
	 * 查询换量系统列表
	 * 
	 * @param appRecommend 换量系统
	 * @return 换量系统
	 */
	@Override
	public List<AppRecommend> selectAppRecommendList(AppRecommend appRecommend) {
		return appRecommendMapper.selectAppRecommendList(appRecommend);
	}

	/**
	 * 新增换量系统
	 * 
	 * @param appRecommend 换量系统
	 * @return 结果
	 */
	@Override
	public int insertAppRecommend(AppRecommend appRecommend) {
		return appRecommendMapper.insertAppRecommend(appRecommend);
	}

	/**
	 * 修改换量系统
	 * 
	 * @param appRecommend 换量系统
	 * @return 结果
	 */
	@Override
	public int updateAppRecommend(AppRecommend appRecommend) {
		int ret = appRecommendMapper.updateAppRecommend(appRecommend);
		redisTemplate.delete(RedisKey.Dict.getAppRecommendKey(appRecommend.getAppid()));
		redisTemplate.delete(RedisKey.Dict.getAppRecommendListKey(appRecommend.getType()));
		return ret;
	}

	/**
	 * 删除换量系统对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteAppRecommendByIds(String ids) {
		return appRecommendMapper.deleteAppRecommendByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除换量系统信息
	 * 
	 * @param appid 换量系统ID
	 * @return 结果
	 */
	@Override
	public int deleteAppRecommendById(Long appid) {
		return appRecommendMapper.deleteAppRecommendById(appid);
	}
}
